<?php

namespace App\Admin\Actions\NewsAction;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use App\Supports\LinkedIn\Client;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;


class BatchNewsExamine extends BatchAction
{
    public $name = '批量审核';
    
    public function handle(Collection $collection)
    {
	   
	   $client = new Client(
				    getenv('LINKDIN_CLIENT_ID'),
				    getenv('LINKDIN_CLIENT_SECRET'),
				);

	 	$client->setRedirectUrl('https://www.xbreakingtechinsight.com');

		$user = User::find(1);
		
		$client->setAccessToken($user->linkdin_token);
    	foreach ($collection as $model) {

    		//if(!empty($model->content_zn) && !empty($model->images) ){
				
				/*$arr = [                                   
		                    'author' => 'urn:li:organization:100897090',
		                    'lifecycleState' => 'PUBLISHED',
		                    'specificContent' => [          
		                        'com.linkedin.ugc.ShareContent' => [
		                            'shareCommentary' => [
		                                'text' => $model->brief_zn
		                            ],
		                            'shareMediaCategory' => 'ARTICLE',
		                            'media' => [
		                                [
		                                    'status' => 'READY',
		                                    'description' => [
		                                        'text' => strip_tags($model->brief_zn)
		                                    ],
		                                    'thumbnails'=> [
		                                    	['url' => img_path($model->images)]
		                                    	
		                                    ],

		                                    //img_path($new['images']
		                                    'originalUrl' => "https://www.xbreakingtechinsight.com/detail/".$model->id,
		                                    'title' => [
		                                        'text' => $model->title_zn
		                                    ]
		                                ]
		                            ]
		                        ]
		                    ],
		                    'visibility' => [
		                        'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC'
		                    ]
		                ];

		               //var_dump($arr); die;
				$share = $client->post(                 
		                'ugcPosts',                         
		                $arr
		            );*/
	       		$model->update([
				    'is_examine' => true,
			    ]);

    		//}

    		
  	 	 }

    	
    	
	    return $this->response()->success('批量审核通过')->refresh();
    }
	
	public function dialog()
	{
		$this->confirm('确定批量审核通过吗?');
	}
}
